<template>
  <view class="box">
    <view class="top">
      <view class="title">
        <image
          class="back"
          src="https://pic.bangbangtongcheng.com/static/back.png"
          @click="back"
        />
        绑定手机号
      </view>
    </view>
    <view
      class=""
      style="width: 130rpx; height: 130rpx; margin: 30rpx auto; margin-top: 120rpx"
    >
      <image
        style="width: 100%; height: 100%; border-radius: 10rpx"
        src="https://pic.bangbangtongcheng.com/static/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%88%86%E4%BA%AB.png"
        mode="widthFix"
        alt=""
      />
    </view>
    <view class="text">为了您的账号安全，请绑定手机号</view>
    <view class="text1">
      <view>*如果您绑定的手机号未注册帮帮同城账号</view>
      <view>将为您自动注册。</view>
    </view>
    <view class="login-box">
      <!-- <view class="box-title">用户快捷登录</view> -->
      <view class="input-box">
        <view class="area">+86</view>
        <view class="line"></view>
        <input
          v-model="phone"
          placeholder="请输入手机号"
          type="number"
          placeholder-class="input-placeholder"
          style="padding-left: 70rpx"
          maxlength="11"
          minlength="11"
        />
      </view>
      <view class="box1">
        <view class="input-box">
          <input
            v-model="Verifys"
            placeholder="请输入验证码"
            placeholder-class="input-placeholder"
            type="number"
          />
          <view class="getcode" @click="getcode">{{ content }}</view>
        </view>
      </view>
      <!-- <view class="agreement">
				<label style="display: flex;">
					<checkbox-group class="checkbox-group" @change="checkboxC">
						<checkbox value="1" class="round blue" :checked="status"
							:style="status ? 'background:#007aff' : ''" />
					</checkbox-group>
					<view class="text">
						<text>登录即同意</text>
						<view class="tags" @click.stop="tags(3)">《用户协议》</view>
						<view class="tags" @click.stop="tags(2)">《隐私协议》</view>
					</view>
				</label>
			</view> -->
      <button
        class="login"
        :disabled="loading"
        :loading="loading"
        hover-class="button-hover"
        @click="login"
      >
        绑定
      </button>
    </view>
    <!-- <cover-view></cover-view> -->
    <view class="motaikuang" v-show="show" @click="show = false">
      <div class="verify" @click.stop="aaa">
        <verify :show="show" @Handle="Handle"></verify>
      </div>
    </view>
    <view class="motaikuang1" v-show="show1" @click="show1 = false">
      <view class="text" @click.stop="aaa">
        <view class="textTitle">{{ text }}</view>
        <scroll-view
          class="scroll-view"
          scroll-y
          :scroll-top="scrollTop"
          @scroll="scrollTop2"
        >
          <!-- <rich-text :nodes="data.content"></rich-text> -->
          <!-- #ifdef MP-WEIXIN -->
          <mp-html :content="data.content"></mp-html>
          <!-- #endif -->
          <!-- #ifndef MP-WEIXIN -->
          <mp-html :content="data.content"></mp-html>
          <!-- #endif -->
        </scroll-view>
      </view>
    </view>
    <uni-popup ref="binds" mode="center" :mask-click="false">
      <view class="binds_frame">
        <view class="binds_frame_t">提示</view>
        <view class="binds_frame_c">当前用户已被冻结，无法登录！</view>
        <view class="binds_frame_b">
          <view class="cancel" @click="jcbdCancel">取消</view>
          <view class="determine" @click="confirmReceipt">去申诉</view>
        </view>
      </view>
    </uni-popup>
    <uni-popup ref="binds1" mode="center" :mask-click="false">
      <view class="binds_frame">
        <view class="binds_frame_t">提示</view>
        <view class="binds_frame_c">当前用户已被冻结，无法登录！</view>
        <view class="binds_frame_b">
          <view class="cancel" @click="jcbdCancel">取消</view>
          <view class="determine" @click="confirmReceipt">去申诉</view>
        </view>
      </view>
    </uni-popup>
    <uni-popup ref="binds2" mode="center">
      <view class="window">
        <view class="window_top">
          <view class="window_title"> 最后一步了，确认要退出登录吗? </view>
        </view>
        <view class="window_btn_box">
          <view class="window_btn" @click="back()">退出</view>
          <view class="window_btn window_btn1" @click="bindsClose2()">继续绑定</view>
        </view>
      </view>
    </uni-popup>
    <view class="motaikuang motaikuang2" v-show="show2" @click="show2 = false">
      <div class="tips" @click.stop="aaa">
        <div class="text">
          为了保护您的合法权益，登录/注册前请仔细阅读并同意以下协议:
          <view class="tags" @click="tags(2)"> 《帮帮同城隐私政策》 </view>
          &
          <view class="tags" @click="tags(3)"> 《帮帮同城用户协议》 </view>
        </div>
        <div class="btns">
          <div class="btn flex_center" @click="show2 = false">不同意</div>
          <div class="btn flex_center" @click="confirmClick">同意</div>
        </div>
      </div>
    </view>
  </view>
</template>

<script>
import Verify from "@/components/VueImageVerify.vue";
//#ifdef H5
import wxshare from "../../utils/index.js";
//#endif
//#ifdef APP-PLUS
// const AlipayModule = uni.requireNativePlugin("Alipaylogin-AlipayModule");
// #endif
// const plug = uni.requireNativePlugin("Html5app-AlipayAuth");
export default {
  data() {
    return {
      phone: "",
      Verifys: "",
      show: false,
      show1: false,
      totalTime: 60,
      password: "",
      content: "获取验证码",
      canClick: true,
      status: true,
      reg_tel: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-9])\d{8}$/,
      loading: false,
      code: "",
      isPassword: false,
      checkBoxs: [],
      type: "",
      text: "",
      data: {},
      system: "",
      platform: "",
      passwordHide: true,
      targetArr: [{}, {}, {}, {}],
      curTarget: 0,
      scrollTop: 0,
      oldScrollTop: 0,
      userIds: "",
      convencid: uni.getStorageSync("convencid") ? uni.getStorageSync("convencid") : "",
      show2: false,
      isLogin: true,
      backNum: 0,
    };
  },
  components: {
    verify: Verify,
  },
  onLoad(options) {
	  console.log('与这里有啥关系？')
    /* #ifdef H5 */
    this.jinzhi();
    /* #endif */
    // 先判断 系统版本
    uni.getSystemInfo({
      success: (res) => {
        this.system = res.system.substring(4, 6);
        this.platform = res.platform;
      },
      fail: (err) => {},
      complete: () => {},
    });
    // #ifdef APP-PLUS
    // this.isAutoLogin()
    // #endif
    return;
    this.$myRequest
      .get("/mob/login/getUserByWXOpenId", {
        openId: "oOuEt5uxj_P1pHc33-OIj03VpLXc",
        convencid: "8ed33ec830089e78715b00e3ca3b688e",
      })
      .then((res) => {
        console.log("获取的信息是:", res);
        this.userInfo = res.userInfo;
        if (!res.userInfo.phone) {
          if (res.userInfo == {} || !res.userInfo.phone) {
            uni.showToast({
              title: "请绑定手机号",
              icon: "none",
              mask: true,
            });
            setTimeout(function () {
              uni.navigateTo({
                url: "/pages/login/register",
              });
            }, 1500);
          }
        } else {
          if (!res.success) {
            uni.showToast({
              title: res.msg,
              icon: "none",
              mask: true,
            });
            if (res.msg == "当前用户已被冻结，无法登录") {
              this.$refs.binds.open();
              this.userIds = res.userInfo.id;
            }
          } else {
            uni.setStorageSync("Pduser", res.userInfo);
            this.$store.dispatch("user/login", res.userInfo);
            setTimeout(function () {
              uni.navigateBack({
                delta: 1,
              });
              uni.closeAuthView(); //关闭授权登录界面
            }, 500);
          }
        }
      });
  },
  onBackPress(options) {
    this.back();
  },
  methods: {
    confirmClick() {
      this.show2 = false;
      uni.closeAuthView();
    },
    jcbdCancel() {
      this.$refs.binds.close();
    },
    confirmReceipt() {
      uni.navigateTo({
        url: "/pages_my/complaint?id=" + this.userIds,
      });
    },
    scrollTop2(e) {
      //记录scroll  位置
      this.oldScrollTop = e.detail.scrollTop;
    },

    hide() {
      this.passwordHide = !this.passwordHide;
    },
    back() {
      if (this.backNum == 0) {
        this.backNum++;
        this.$refs.binds2.open();
        return;
      }
      this.backNum++;
	  uni.navigateTo({
	    url: '/pages/login/login',
	  })
      // uni.navigateBack({
      //   delta: 1,
      // });
    },
    bindsClose2() {
      this.$refs.binds2.close();
    },
    aaa() {},
    codes(code) {
      this.Verifys = code;
    },
    Handle(success) {
      console.log(success, "登录");
      if (!this.canClick) return; //改动的是这两行代码
      this.canClick = false;
      this.show = false;
      this.content = this.totalTime + "s后重新发送";
      this.$myRequest
        .get("/mob/login/phoneVerification.do", {
          phone: this.phone,
        })
        .then((res) => {
          if (res.success) {
            this.code = res.CODE;
          } else {
            uni.showToast({
              title: res.msg,
              icon: "none",
              mask: true,
            });
          }
          console.log(res);
        });
      let clock = setInterval(() => {
        this.totalTime--;
        this.content = this.totalTime + "s后重新发送";
        if (this.totalTime < 0) {
          clearInterval(clock);
          this.content = "重新发送验证码";
          this.totalTime = 60;
          this.canClick = true; //这里重新开启
        }
      }, 1000);
    },
    // 判断是否支持一键登陆
    isAutoLogin() {
      let _that = this;
      uni.showLoading({
        title: "获取手机号中",
      });
      uni.getProvider({
        //获取可用的服务提供商
        service: "oauth",
        success: function (res) {
          console.log(res.provider); // ['weixin', qq', 'univerify']
        },
      });
      uni.preLogin({
        //预登录
        provider: "univerify", //用手机号登录
        success() {
          console.log("预登录成功", _that.platform);
          uni.hideLoading();
          _that.autoStatus = true;
          if (_that.platform == "ios" || _that.platform == "IOS") {
            _that.submitlogin();
          } else {
            _that.submitAndroid();
          }
        },
        fail(err) {
          //预登录失败
          console.log("预登录失败", err);
          uni.hideLoading();
          _that.autoStatus = false;
          if (!_that.autoStatus) {
            // uni.showToast({
            // 	title: err.errMsg,
            // 	icon: "none",
            // 	mask: true
            // });
            // uni.navigateTo({
            //   url: "/pages/login/login"
            // });
            return;
          }
        },
      });
    },
    submitlogin() {
      let that = this;
      const univerifyManager = uni.getUniverifyManager();
      univerifyManager.login({
        //正式登录，弹出授权窗
        // provider: 'univerify',
        univerifyStyle: {
          // 自定义登录框样式
          fullScreen: true, // 是否全屏显示，true表示全屏模式，false表示非全屏模式，默认值为false。
          backgroundColor: "#ffffff", // 授权页面背景颜色，默认值：#ffffff
          icon: {
            path: "/static/logo.png", // 自定义显示在授权框中的logo，仅支持本地图片 默认显示App logo
          },
          phoneNum: {
            color: "#2281F5", // 手机号文字颜色 默认值：#000000
          },
          authButton: {
            normalColor: "#64b6a8", // 授权按钮正常状态背景颜色 默认值：#3479f5
            highlightColor: "#64b6a8", // 授权按钮按下状态背景颜色 默认值：#2861c5（仅ios支持）
            disabledColor: "#64b6a8", // 授权按钮不可点击时背景颜色 默认值：#73aaf5（仅ios支持）
            textColor: "#ffffff", // 授权按钮文字颜色 默认值：#ffffff
            title: "本机号码一键登录", // 授权按钮文案 默认值：“本机号码一键登录”
          },
          otherLoginButton: {
            visible: true, // 是否显示其他登录按钮，默认值：true
            normalColor: "", // 其他登录按钮正常状态背景颜色 默认值：透明
            highlightColor: "", // 其他登录按钮按下状态背景颜色 默认值：透明
            textColor: "#656565", // 其他登录按钮文字颜色 默认值：#656565
            title: "", // 其他登录方式按钮文字 默认值：“其他登录方式”
            borderColor: "", //边框颜色 默认值：透明（仅iOS支持）
            borderRadius: "0px", // 其他登录按钮圆角 默认值："24px" （按钮高度的一半）
          },
          privacyTerms: {
            defaultCheckBoxState: false, // 条款勾选框初始状态 默认值： true
            uncheckedImage: "static/noSelect.png", // 可选 条款勾选框未选中状态图片（仅支持本地图片 建议尺寸 24x24px）(3.2.0+ 版本支持)
            checkedImage: "static/select.png", // 可选 条款勾选框选中状态图片（仅支持本地图片 建议尺寸24x24px）(3.2.0+ 版本支持)
            checkBoxSize: "20", // 可选 条款勾选框大小，仅android支持
            textColor: "#666666", // 文字颜色 默认值：#BBBBBB
            termsColor: "#64B6A8", //  协议文字颜色 默认值： #5496E3
            prefix: "已阅读并同意", // 条款前的文案 默认值：“我已阅读并同意”
            suffix: " ", // 条款后的文案 默认值：“并使用本机号码登录”
            privacyItems: [
              // 自定义协议条款，最大支持2个，需要同时设置url和title. 否则不生效
              {
                url: "https://bangbangtongcheng.com/agreement.html", // 点击跳转的协议详情页面
                title: "帮帮同城隐私协议", // 协议名称
              },
              {
                url: "https://bangbangtongcheng.com/agreement2.html", // 点击跳转的协议详情页面
                title: "帮帮同城用户协议", // 协议名称
              },
            ],
          },
          buttons: {
            // 自定义页面下方按钮仅全屏模式生效（3.1.14+ 版本支持）
            iconWidth: "45px", // 图标宽度（高度等比例缩放） 默认值：45px
            list: [
              {
                provider: "phone",
                iconPath: "/static/phone.png", // 图标路径仅支持本地图片
              },
              {
                provider: "weixin",
                iconPath: "/static/wx.png", // 图标路径仅支持本地图片
              },
              {
                provider: "apple",
                iconPath: "/static/apple.png", // 图标路径仅支持本地图片
              },
              // {
              //   provider: "Alipay",
              //   iconPath: "/static/Alipay.png", // 图标路径仅支持本地图片
              // },
            ],
          },
        },
        success(res) {
          // 正式登录成功
          console.log("-------------", res.authResult); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}

          // 在得到access_token后，通过callfunction调用云函数
          uniCloud.callFunction({
            name: "uni-getPhone", // 云函数名称
            data: {
              //传给云函数的参数
              access_token: res.authResult.access_token, // 客户端一键登录接口返回的access_token
              openid: res.authResult.openid, // 客户端一键登录接口返回的openid
            },
            success(callRes) {
              // console.log('调用云函数成功' + JSON.stringify(callRes))
              console.log("手机号登陆" + callRes.result.phoneNumber);
              that.$myRequest
                .post("/mob/login/phoneOneClickLogin", {
                  phone: callRes.result.phoneNumber,
                  convencid: that.convencid,
                })
                .then((res) => {
                  console.log("手机号登陆结果:" + res);
                  if (!res.success) {
                    uni.showToast({
                      title: res.msg,
                      icon: "none",
                      mask: true,
                    });
                    setTimeout(function () {
                      uni.closeAuthView(); //关闭授权登录界面
                      if (res.msg == "当前用户已被冻结，无法登录") {
                        that.$refs.binds.open();
                        that.userIds = res.userInfo.id;
                      }
                    }, 1000);
                  } else {
                    uni.setStorageSync("Pduser", res.userInfo);
                    that.$store.dispatch("user/login", res.userInfo);
                    setTimeout(function () {
                      uni.closeAuthView() //关闭授权登录界面
                      uni.switchTab({
                        url: '/pages/index/index',
                      })
                    }, 500);
                    uni.closeAuthView(); //关闭授权登录界面
                  }
                });
            },
            fail(callErr) {
              uni.showToast({
                title: "授权失败",
                icon: "none",
                mask: true,
              });
              console.log("调用云函数出错" + callErr);
              uni.closeAuthView(); //关闭授权登录界面
            },
            // complete() {
            // 	uni.closeAuthView() //关闭授权登录界面
            // }
          });
        },
        fail(err) {
          // 正式登录失败
          // if (err.provider=='phone') {
          // 	uni.closeAuthView() //关闭授权登录界面
          // }else if(err.provider=='weixin'){
          // 	that.handleThirdLoginApp()
          // 	return
          // }else if(err.provider=='apple'){
          // 	that.appleLogin()
          // 	return
          // }else if(err.provider=='Alipay'){
          // 		that.alipayLogin()
          // 		return
          // }
        },
      });
      const callback = (err) => {
        // 获取一键登录弹框协议勾选状态
        console.log("点击事件: ", err);
        univerifyManager.getCheckBoxState({
          success(res) {
            console.log("getCheckBoxState res: ", res);
            if (res.state) {
              // 关闭一键登录弹框
              univerifyManager.close();
              if (err.provider == "phone") {
                uni.closeAuthView(); //关闭授权登录界面
                // that.show2 = true
              } else if (err.provider == "weixin") {
                that.handleThirdLoginApp();
                return;
              } else if (err.provider == "apple") {
                that.appleLogin();
                return;
              }
              // else if (err.provider == "Alipay") {
              //   that.alipayLogin();
              //   return;
              // }
            } else {
              uni.showToast({
                title: "请勾选服务协议",
                icon: "none",
                mask: true,
              });
            }
          },
        });
      };
      // 订阅自定义按钮点击事件
      univerifyManager.onButtonsClick(callback);
    },
    // 支付宝登录
    alipayLogin() {
      let that = this;
      const plug = uni.requireNativePlugin("Html5app-AlipayAuth");
      if (that.platform == "ios" || that.platform == "IOS") {
        plug.login({ appid: "2021003144632733", urlscheme: "convenAlilogin" }, (ret) => {
          if (ret.code == 0) {
            console.log(ret.result.auth_code, "-------");
            let auth_code = ret.result.auth_code;
            that.$myRequest
              .get("/mob/login/aliLogin", {
                code: auth_code,
                convencid: that.convencid,
              })
              .then((res) => {
                console.log(res);
                if (res.userInfo.phone) {
                  uni.showLoading({
                    title: "登录中...",
                  });
                  if (!res.success) {
                    uni.showToast({
                      title: res.msg,
                      icon: "none",
                      mask: true,
                    });
                  } else {
                    uni.setStorageSync("Pduser", res.userInfo);
                    that.$store.dispatch("user/login", res.userInfo);
                    setTimeout(function () {
                      uni.closeAuthView() //关闭授权登录界面
                      uni.switchTab({
                        url: '/pages/index/index',
                      })
                    }, 500);
                  }
                } else {
                  let userInfo = {
                    nickname: res.userInfo.nikeName,
                    headimgurl: res.userInfo.image,
                    zfbOpenid: res.userInfo.zfbOpenid,
                  };
                  uni.setStorageSync("userInfo", JSON.stringify(userInfo));
                  uni.showToast({
                    title: "未绑定手机号，前往绑定手机号",
                    icon: "none",
                    mask: true,
                  });
                  setTimeout(function () {
                    uni.navigateTo({ url: "/pages/login/register" });
                  }, 1500);
                }
              });
          } else {
            uni.showToast({
              title: "授权失败",
              icon: "none",
              mask: true,
            });
          }
        });
      } else {
        plug.login({ appid: "2021003144632733" }, (ret) => {
          if (ret.code == 0) {
            console.log(ret.result.auth_code, "-------");
            let auth_code = ret.result.auth_code;
            that.$myRequest
              .get("/mob/login/aliLogin", {
                code: auth_code,
                convencid: that.convencid,
              })
              .then((res) => {
                console.log(res);
                if (res.userInfo.phone) {
                  uni.showLoading({
                    title: "登录中...",
                  });
                  if (!res.success) {
                    uni.showToast({
                      title: res.msg,
                      icon: "none",
                      mask: true,
                    });
                    setTimeout(function () {
                      uni.closeAuthView(); //关闭授权登录界面
                    }, 1000);
                  } else {
                    uni.setStorageSync("Pduser", res.userInfo);
                    that.$store.dispatch("user/login", res.userInfo);
                    setTimeout(function () {
                      uni.closeAuthView() //关闭授权登录界面
                      uni.switchTab({
                        url: '/pages/index/index',
                      })
                    }, 500);
                  }
                } else {
                  let userInfo = {
                    nickname: res.userInfo.nikeName,
                    headimgurl: res.userInfo.image,
                    zfbOpenid: res.userInfo.zfbOpenid,
                  };
                  uni.setStorageSync("userInfo", JSON.stringify(userInfo));
                  uni.showToast({
                    title: "未绑定手机号，前往绑定手机号",
                    icon: "none",
                    mask: true,
                  });
                  setTimeout(function () {
                    uni.navigateTo({ url: "/pages/login/register" });
                  }, 1500);
                }
              });
          } else {
            uni.showToast({
              title: "授权失败",
              icon: "none",
              mask: true,
            });
          }
        });
      }
    },
    submitAndroid() {
      const univerifyManager = uni.getUniverifyManager();
      let that = this;
      univerifyManager.login({
        //正式登录，弹出授权窗
        // provider: 'univerify',
        univerifyStyle: {
          // 自定义登录框样式
          fullScreen: true, // 是否全屏显示，true表示全屏模式，false表示非全屏模式，默认值为false。
          backgroundColor: "#ffffff", // 授权页面背景颜色，默认值：#ffffff
          icon: {
            path: "static/logo.png", // 自定义显示在授权框中的logo，仅支持本地图片 默认显示App logo
          },
          phoneNum: {
            color: "#2281F5", // 手机号文字颜色 默认值：#000000
          },
          authButton: {
            normalColor: "#64b6a8", // 授权按钮正常状态背景颜色 默认值：#3479f5
            highlightColor: "#64b6a8", // 授权按钮按下状态背景颜色 默认值：#2861c5（仅ios支持）
            disabledColor: "#64b6a8", // 授权按钮不可点击时背景颜色 默认值：#73aaf5（仅ios支持）
            textColor: "#ffffff", // 授权按钮文字颜色 默认值：#ffffff
            title: "本机号码一键登录", // 授权按钮文案 默认值：“本机号码一键登录”
          },
          otherLoginButton: {
            visible: true, // 是否显示其他登录按钮，默认值：true
            normalColor: "", // 其他登录按钮正常状态背景颜色 默认值：透明
            highlightColor: "", // 其他登录按钮按下状态背景颜色 默认值：透明
            textColor: "#656565", // 其他登录按钮文字颜色 默认值：#656565
            title: "", // 其他登录方式按钮文字 默认值：“其他登录方式”
            borderColor: "", //边框颜色 默认值：透明（仅iOS支持）
            borderRadius: "0px", // 其他登录按钮圆角 默认值："24px" （按钮高度的一半）
          },
          privacyTerms: {
            defaultCheckBoxState: false, // 条款勾选框初始状态 默认值： true
            uncheckedImage: "static/noSelect.png", // 可选 条款勾选框未选中状态图片（仅支持本地图片 建议尺寸 24x24px）(3.2.0+ 版本支持)
            checkedImage: "static/select.png", // 可选 条款勾选框选中状态图片（仅支持本地图片 建议尺寸24x24px）(3.2.0+ 版本支持)
            checkBoxSize: "18", // 可选 条款勾选框大小，仅android支持
            textColor: "#666666", // 文字颜色 默认值：#BBBBBB
            termsColor: "#64B6A8", //  协议文字颜色 默认值： #5496E3
            prefix: "已阅读并同意", // 条款前的文案 默认值：“我已阅读并同意”
            suffix: " ", // 条款后的文案 默认值：“并使用本机号码登录”
            privacyItems: [
              // 自定义协议条款，最大支持2个，需要同时设置url和title. 否则不生效
              {
                url: "https://bangbangtongcheng.com/agreement.html", // 点击跳转的协议详情页面
                title: "帮帮同城隐私协议", // 协议名称
              },
              {
                url: "https://bangbangtongcheng.com/agreement2.html", // 点击跳转的协议详情页面
                title: "帮帮同城用户协议", // 协议名称
              },
            ],
          },
          buttons: {
            // 自定义页面下方按钮仅全屏模式生效（3.1.14+ 版本支持）
            iconWidth: "45px", // 图标宽度（高度等比例缩放） 默认值：45px
            list: [
              {
                provider: "phone",
                iconPath: "/static/phone.png", // 图标路径仅支持本地图片
              },
              {
                provider: "weixin",
                iconPath: "/static/wx.png", // 图标路径仅支持本地图片
              },
              // {
              //   provider: "Alipay",
              //   iconPath: "/static/Alipay.png", // 图标路径仅支持本地图片
              // },
            ],
          },
        },
        success(res) {
          // 正式登录成功
          console.log("正式登录成功", res.authResult); // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}

          // 在得到access_token后，通过callfunction调用云函数
          uniCloud.callFunction({
            name: "uni-getPhone", // 云函数名称
            data: {
              //传给云函数的参数
              access_token: res.authResult.access_token, // 客户端一键登录接口返回的access_token
              openid: res.authResult.openid, // 客户端一键登录接口返回的openid
            },
            success(callRes) {
              // console.log('调用云函数成功' + JSON.stringify(callRes))
              console.log("手机号登陆" + callRes.result.phoneNumber);
              that.$myRequest
                .post("/mob/login/phoneOneClickLogin", {
                  phone: callRes.result.phoneNumber,
                  convencid: that.convencid,
                })
                .then((res) => {
                  console.log("手机号登陆结果:" + res);
                  if (!res.success) {
                    uni.showToast({
                      title: res.msg,
                      icon: "none",
                      mask: true,
                    });
                    setTimeout(function () {
                      uni.closeAuthView(); //关闭授权登录界面
                      if (res.msg == "当前用户已被冻结，无法登录") {
                        that.$refs.binds.open();
                        that.userIds = res.userInfo.id;
                      }
                    }, 1000);
                  } else {
                    uni.setStorageSync("Pduser", res.userInfo);
                    that.$store.dispatch("user/login", res.userInfo);
                    setTimeout(function () {
                      uni.closeAuthView() //关闭授权登录界面
                      uni.switchTab({
                        url: '/pages/index/index',
                      })
                    }, 500);
                  }
                });
            },
            fail(callErr) {
              uni.showToast({
                title: "授权失败",
                icon: "none",
                mask: true,
              });
              console.log("调用云函数出错" + callErr);
            },
            // complete() {
            // 	uni.closeAuthView() //关闭授权登录界面
            // }
          });
        },
        fail(err) {
          // 正式登录失败
          // if (err.provider=='phone') {
          // 	uni.closeAuthView() //关闭授权登录界面
          // }else if(err.provider=='weixin'){
          // 	that.handleThirdLoginApp()
          // 	return
          // }else if(err.provider=='Alipay'){
          // 	that.alipayLogin()
          // 	return
          // }
        },
      });
      const callback = (err) => {
        // 获取一键登录弹框协议勾选状态
        console.log("点击事件: ", err);
        univerifyManager.getCheckBoxState({
          success(res) {
            console.log("getCheckBoxState res: ", res);
            if (res.state) {
              // 关闭一键登录弹框
              univerifyManager.close();
              // that.show2 = true
              if (err.provider == "phone") {
                uni.closeAuthView(); //关闭授权登录界面
              } else if (err.provider == "weixin") {
                that.handleThirdLoginApp();
                return;
              }
              // else if (err.provider == "Alipay") {
              //   that.alipayLogin();
              //   return;
              // }
            } else {
              uni.showToast({
                title: "请勾选服务协议",
                icon: "none",
                mask: true,
              });
            }
          },
        });
      };
      // 订阅自定义按钮点击事件
      univerifyManager.onButtonsClick(callback);
    },
    passwordC() {
      this.isPassword = !this.isPassword;
    },
    jinzhi() {
      let _this = this;
      let param = window.location.href.split("#")[0];
      uni.request({
        method: "post",
        data: {
          url: param,
        },
        header: {
          "content-type": "application/x-www-form-urlencoded",
        },
        url: "https://www.bangbangtongcheng.com/conven//mob/login/getJsTicket.do",
        success(re) {
          _this.jinzhifx(re.data);
        },
      });
    },
    jinzhifx(data) {
      wxshare.config({
        debug: false, //是否打开调试
        appId: data.appId, // 公众号的唯一标识
        timestamp: data.timestamp, // 生成签名的时间戳
        nonceStr: data.nonce, // ，生成签名的随机串
        signature: data.signature, // 签名
        jsApiList: ["hideMenuItems"],
      });
      // 禁止分享
      wxshare.hideMenuItems({
        // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
        menuList: [
          "menuItem:share:appMessage",
          "menuItem:share:timeline",
          "menuItem:share:timeline",
          "menuItem:share:qq",
          "menuItem:favorite",
          "menuItem:share:QZone",
          "menuItem:openWithSafari",
        ],
      });
    },
    // 苹果登录
    appleLogin() {
      var that = this;
      // 判断是 iOS13版本
      uni.login({
        provider: "apple",
        success: (loginRes) => {
          uni.getUserInfo({
            provider: "apple",
            success: (userInfoRes) => {
              console.log(userInfoRes);
              let data = userInfoRes.userInfo;
              let userInfo = {
                openid: data.openId,
                headimgurl: "",
                nickname: "苹果用户",
              };
              uni.setStorageSync("userInfo", JSON.stringify(userInfo));
              // console.log("aaaaaaa");
              that.getuniID();
            },
            fail: (err) => {},
          });
        },
        fail: (err) => {},
      });
    },

    handleThirdLoginApp() {
      console.log("App微信拉起授权");
      var that = this;
      uni.getProvider({
        service: "oauth",
        success: function (res) {
          console.log(res.provider); //支持微信、qq和微博等
          if (res.provider.indexOf("weixin")) {
            uni.login({
              provider: "weixin",
              success: function (loginRes) {
                console.log("App微信获取用户信息成功", loginRes);
                that.getApploginData(loginRes); //请求登录接口方法
              },
              fail: function (res) {
                console.log("App微信获取用户信息失败", res);
                uni.showToast({
                  title: "测试环境，无法使用",
                  icon: "none",
                });
              },
            });
          }
        },
      });
    },
    getApploginData(data) {
      var that = this;
      //这边是前端自己去调微信用户信息的接口，根据接口需要请求，如果不需要前端去获取的话就交给后端，可省去次操作
      uni.request({
        url:
          "https://api.weixin.qq.com/sns/userinfo?access_token=" +
          data.authResult.access_token +
          "&openid=" +
          data.authResult.openid,
        method: "GET",
        dataType: "json",
        header: {
          "content-type": "application/x-www-form-urlencoded", // 默认值
        },
        success(res) {
          console.log("【登录回调啾啾啾】", res);
          let data = res.data;
          let userInfo = {
            openid: data.unionid,
            headimgurl: data.headimgurl,
            nickname: data.nickname,
          };
          uni.setStorageSync("userInfo", JSON.stringify(userInfo));
          // console.log("aaaaaaa");
          that.getuniID();
          // uni.setStorageSync("userInfo", JSON.stringify(res.data));
          // uni.showToast({
          //   title: "账号未注册，请完善信息",
          //   icon: "none",
          //   mask: true,
          // });
          // uni.navigateTo({ url: "/pages/login/register" });
          // if (res.data.phone) {
          //   uni.setStorageSync("phone", res.data.phone);
          //   uni.showToast({
          //     title: "登录成功",
          //     icon: "none",
          //     mask: true,
          //   });
          //   setTimeout(function () {
          //     uni.reLaunch({ url: "/pages/index/index" });
          //   }, 1500);
          // } else {
          //   uni.setStorageSync("userInfo", JSON.stringify(res.data));
          //   uni.showToast({
          //     title: "账号未注册，请完善信息",
          //     icon: "none",
          //     mask: true,
          //   });
          //   setTimeout(function () {
          //     uni.navigateTo({ url: "/pages/login/register" });
          //   }, 1500);
          // }
        },
        fail() {},
      });
    },
    getuniID() {
      let that = this;
      let userInfo = JSON.parse(uni.getStorageSync("userInfo"));
      // // #ifdef MP || H5
      // userInfo = JSON.parse(uni.getStorageSync("userInfo"));
      // //#endif
      // //#ifdef APP-PLUS
      // userInfo = JSON.parse(uni.getStorageSync("userInfo"));
      // // #endif
      console.log("openid是:", userInfo.openid);
      this.$myRequest
        .get("/mob/login/getUserByApplyId", {
          openId: userInfo.openid,
          convencid: that.convencid,
        })
        .then((res) => {
          console.log("获取的信息是:", res);
          this.userInfo = res.userInfo;
          if (!res.userInfo.phone) {
            if (res.userInfo == {} || !res.userInfo.phone) {
              // uni.showToast({
              // 	title: "请绑定手机号",
              // 	icon: "none",
              // 	mask: true
              // });
              setTimeout(function () {
                uni.navigateTo({
                  url: "/pages/login/register",
                });
              }, 1500);
            }
          } else {
            if (!res.success) {
              uni.showToast({
                title: res.msg,
                icon: "none",
                mask: true,
              });
              if (res.msg == "当前用户已被冻结，无法登录") {
                this.$refs.binds.open();
                this.userIds = res.userInfo.id;
              }
            } else {
              uni.setStorageSync("Pduser", res.userInfo);
              that.$store.dispatch("user/login", res.userInfo);
              setTimeout(function () {
                uni.closeAuthView() //关闭授权登录界面
                uni.switchTab({
                  url: '/pages/index/index',
                })
              }, 500);
            }
          }
        });
    },
    register() {
      uni.navigateTo({
        url: "/pages/login/register",
      });
    },
    login() {
      let userInfo = JSON.parse(uni.getStorageSync("userInfo"));
      let that = this;
      if (this.loading == true) return;
      // if (!this.checkBoxs.length) {
      // 	uni.showModal({
      // 		title: "",
      // 		content: "请同意用户条款",
      // 		showCancel: false,
      // 		success: function (res) {
      // 			if (res.confirm) {
      // 				console.log("用户点击确定");
      // 			} else if (res.cancel) {
      // 				console.log("用户点击取消");
      // 			}
      // 		}
      // 	});
      // 	return;
      // }
      this.loading = true;
      if (!this.reg_tel.test(this.phone)) {
        uni.showToast({
          title: "请填写正确的手机号码",
          icon: "none",
          mask: true,
        });
        this.loading = false;
        return;
      }
      let disabled = true;
      if (this.isPassword) {
        if (this.password == "" || this.password == undefined) {
          uni.showToast({
            title: "请输入密码",
            icon: "none",
            mask: true,
          });
          disabled = false;
          this.loading = false;
        }
      } else {
        if (this.Verifys != this.code) {
          uni.showToast({
            title: "验证码不正确，请重新填写",
            icon: "none",
            mask: true,
          });
          disabled = false;
          this.loading = false;
        }
      }
      if (!disabled) return;
      console.log("123123213" + that.convencid);
      this.$myRequest
        .post("/mob/login/phoneLogin", {
          phone: this.phone,
          loginType: this.isPassword ? "2" : "1",
          phoneCode: this.Verifys,
          password: this.password,
          convencid: that.convencid,
          wxOpenid: userInfo.openid ? userInfo.openid : "",
          openId: userInfo.openIdH5 || "",
          zfbOpenid: userInfo.zfbOpenid ? userInfo.zfbOpenid : "",
          pdOpenid: userInfo.pdOpenid ? userInfo.pdOpenid : "",
        })
        .then((res) => {
          that.loading = false;
          if (!res.success) {
            uni.showToast({
              title: res.msg,
              icon: "none",
              mask: true,
            });
            if (res.msg == "当前用户已被冻结，无法登录") {
              this.$refs.binds.open();
              this.userIds = res.userInfo.id;
            }
            if (res.code == 401) {
              console.log(2222222);
              this.isLogin = false;
            }
          } else {
            console.log(res.userInfo, "手机号登陆");
            // uni.navigateTo({ url: "/pages/index/index" });
            // uni.setStorageSync("phone", that.phone);
            uni.setStorageSync("Pduser", res.userInfo);
            that.$store.dispatch("user/login", res.userInfo);
            uni.showToast({
              title: "绑定成功",
              icon: "none",
              mask: true,
            });
            if (res.userInfo.businessType == 1) {
              this.$myRequest
                .get("/mob/user/isMarkResignation", {
                  userId: res.userInfo.id,
                })
                .then((res) => {
                  if (res.code == 200) {
                    console.log(res);
                    getApp().globalData.confirm = res.confirm;
                  }
                });
            } else {
              this.$myRequest
                .get("/api/mobile/vehicleOwner/getWhetherMarkResignationByUserId", {
                  userId: res.userInfo.id,
                })
                .then((res) => {
                  if (res.code == 200) {
                    getApp().globalData.confirm = res.confirm;
                  }
                });
            }
			 console.log('走着路吗');
            setTimeout(function () {
              // uni.navigateBack({
              //   delta: 2,
              // });
			  //源代码是回退2步 绑定成功相当于登录成功 直接跳转个人中心
			  uni.switchTab({
			    url: '/pages/index/index',
			  })
            }, 1500);
          }
        })
        .catch((err) => {
          this.loading = false;
          if (err.msg == "当前用户已被冻结，无法登录") {
            this.$refs.binds.open();
            this.userIds = err.userInfo.id;
          }
          if (err.code == 401) {
            console.log(2222222);
            this.isLogin = false;
          }
        });
    },
    checkboxC(e) {
      // console.log(e);
      this.checkBoxs = e.detail.value;
    },
    async tags(type) {
      if (type == this.curTarget) {
        this.show1 = true;
        return;
      }
      this.type = type;
      if (type == 2) {
        this.text = "隐私协议";
      } else if (type == 3) {
        this.text = "用户服务协议";
      }
      await this.getContent();
      this.curTarget = type;
      // this.show1 = true;
    },
    getContent() {
      let _this = this;
      _this.$myRequest
        .get("/mob/user/getText", {
          type: this.type,
        })
        .then((res) => {
          this.data = res.list[0];
          //视图会发生重新渲染
          this.scrollTop = this.oldScrollTop;
          //当视图渲染结束 重新设置为0
          this.$nextTick(() => {
            this.show1 = true;
            this.scrollTop = 0;
          });
        });
    },
    getcode() {
      console.log(this.status);
      this.phone = this.phone.trim();
      if (!this.reg_tel.test(this.phone)) {
        uni.showToast({
          title: "请填写正确的手机号码",
          icon: "none",
          mask: true,
        });
        return;
      }
      if (!this.canClick) return;
      this.show = true;
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  min-height: 100vh;
  background: #fff;
}

.binds_frame {
  width: 600rpx;
  background-color: #ffffff;
  padding-bottom: 50rpx;
  border-radius: 10rpx;
  text-align: center;
  .binds_frame_t {
    font-size: 30rpx;
    font-weight: 550;
    color: #000000;
    padding: 0 46rpx;
    padding-top: 36rpx;
  }
  .binds_frame_c {
    width: 500rpx;
    margin: 0 auto;
    font-size: 28rpx;
    font-weight: 400;
    color: #64b6a8;
    margin-top: 30rpx;
    margin-bottom: 50rpx;
  }
  .binds_frame_b {
    display: flex;
    align-items: center;
    justify-content: space-around;
    .cancel {
      width: 210rpx;
      height: 70rpx;
      background-color: #64b6a8;
      border-radius: 10rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 30rpx;
      font-weight: 400;
      color: #fff;
    }
    .determine {
      width: 210rpx;
      height: 70rpx;
      background-color: #000;
      border-radius: 10rpx;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 30rpx;
      font-weight: 400;
      color: #fff;
    }
  }
}
.top {
  padding-top: 88rpx;
  background: transparent;

  .title {
    // text-align: center;
    height: 88rpx;
    line-height: 88rpx;
    font-size: 36rpx;
    padding: 0 37rpx;
    text-align: center;
    font-size: 34rpx;
    color: #000;
  }

  .back {
    width: 40rpx;
    height: 40rpx;
  }
}

.login-box {
  padding: 90rpx 100rpx 0;

  .box-title {
    line-height: 75rpx;
    font-size: 46rpx;
    margin-bottom: 105rpx;
    color: #64b6a8;
    font-weight: 600;
  }

  .input-box {
    height: 65rpx;
    border-bottom: 1rpx solid #d0d0d0;
    position: relative;
    margin-bottom: 52rpx;

    input {
      width: 100%;
      height: 64rpx;
      line-height: 64rpx;
      color: #333;
      font-size: 28rpx;
    }

    .area {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      color: #333;
      left: 0;
    }

    .line {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      color: #333;
      left: 60rpx;
      height: 30rpx;
      width: 2rpx;
      background: #333;
    }

    .getcode {
      position: absolute;
      top: 50%;
      right: 0;
      transform: translateY(-50%);
      color: #64b6a8;
      font-size: 28rpx;
      z-index: 10;
    }
  }

  .agreement {
    display: flex;
    padding-left: 10rpx;
    padding-top: 50rpx;
    font-size: 24rpx;
    align-items: center;

    .checkbox-group {
      // width: 50rpx !important;
      // height: 40rpx !important;
      /* #ifdef MP */
      width: 50rpx !important;
      height: 50rpx !important;
      /* #endif */
      /* #ifdef APP-PLUS || H5 */
      width: 32rpx !important;
      height: 32rpx !important;
      /* #endif */
    }

    .text {
      display: flex;
      align-items: center;
      line-height: 37rpx;
      margin-left: 10rpx;
    }

    .tags {
      color: #64b6a8;
    }
  }

  .login {
    width: 100%;
    height: 76rpx;
    line-height: 76rpx;
    background: #64b6a8;
    color: #fff;
    border-radius: 100rpx;
    margin-top: 38rpx;
    margin-bottom: 24rpx;
  }

  .flex-center {
    display: flex;
    justify-content: center;
    align-items: center;
    .line {
      margin: 0 10rpx;
    }
    view {
      font-size: 26rpx;
      line-height: 37rpx;
      color: #666666;
    }
  }
}

.bottom-nav {
  // position: fixed;
  // bottom: 0;
  // left: 0;

  width: 100%;
  padding: 160rpx 0 80rpx;

  .bottom-top {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: 40rpx;
    width: 550rpx;
    margin: 0 auto 58rpx;

    .line {
      width: 100rpx;
      height: 2rpx;
      background: #666;
    }

    .title-text {
      font-size: 28rpx;
      color: #666;
    }
  }

  .bottom-loginType {
    display: flex;
    justify-content: center;
    /* align-items: center; */
    align-items: flex-start;

    .type {
      width: 120rpx;
      text-align: center;
      margin-right: 60rpx;

      image {
        width: 80rpx;
        height: 80rpx;
      }

      view {
        font-size: 28rpx;
        line-height: 40rpx;
        margin-top: 10rpx;
      }
    }

    .sign-in-with-apple {
      width: 260rpx;
      text-align: center;
      /* margin-right: 60rpx; */
      display: flex;
      padding: 3px 5px;
      border: rgb(49, 49, 49) 1px solid;
      border-radius: 6px;
      margin-top: 4px;

      image {
        width: 40rpx;
        height: 40rpx;
      }

      view {
        font-size: 24rpx;
        line-height: 50rpx;
        margin-left: 10rpx;
        font-weight: 600;
        /* margin-top: 10rpx; */
      }
    }

    .type:last-child {
      margin-right: 0;
    }
  }
}

.motaikuang {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;

  .verify {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

.motaikuang1 {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;

  .text {
    position: fixed;
    bottom: 0;
    width: 100%;
    background: #fff;
    left: 0;
    padding-top: 60rpx;
    padding-bottom: 100rpx;
    border-radius: 50rpx 50rpx 0 0;

    .textTitle {
      font-size: 36rpx;
      line-height: 50rpx;
      text-align: center;
      margin-bottom: 50rpx;
    }

    .scroll-view {
      height: 700rpx;
      margin: 0 auto;
      width: 630rpx;
    }
  }
}

.checked {
  background: #007aff;
}

/deep/.uni-checkbox-input-checked {
  background-color: #64b6a8 !important;
  border-color: #64b6a8 !important;
}

/deep/ .uni-checkbox-input {
  border-color: #666;
  background: #fff;
}
.motaikuang {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 20;

  .verify {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

.motaikuang2 {
  .tips {
    position: fixed;
    bottom: 0;
    width: 100%;
    background: #fff;
    left: 0;
    padding: 40rpx 30rpx 100rpx;
    border-radius: 50rpx 50rpx 0 0;
    .text {
      margin-bottom: 48rpx;
    }
    .btns {
      display: flex;
      .btn {
        height: 90rpx;
        width: 50%;
        &:first-child {
          background: #f2f2f2;
          border-radius: 10rpx 0rpx 0rpx 10rpx;
        }
        &:last-child {
          background: #64b6a8;
          color: #fff;
          border-radius: 0rpx 10rpx 10rpx 0rpx;
        }
      }
    }
  }
  .tags {
    color: #64b6a8;
    display: inline-block;
  }
}
.text {
  margin-bottom: 30rpx;
  color: #666666;
  font-size: 30rpx;
  line-height: 42rpx;
  text-align: center;
}
.text1 {
  color: #000000;
  font-size: 26rpx;
  line-height: 36rpx;
  text-align: center;
}
.window {
  width: 600rpx;
  background: #fff;
  border-radius: 10rpx;
  padding-top: 32rpx;
  position: relative;
  overflow: hidden;
  .window_top {
    // margin: 0 30rpx;
    padding: 40rpx;
  }
  .window_title {
    color: #3d3d3d;
    font-size: 30rpx;
    text-align: center;
    margin-bottom: 30rpx;
  }
  .window_close {
    width: 40rpx;
    height: 40rpx;
    top: 20rpx;
    right: 20rpx;
    position: absolute;
  }
  .window_text {
    margin-bottom: 20rpx;
    font-size: 28rpx;
    color: #3d3d3d;
  }
  .text_widnow {
    padding: 16rpx;
    min-height: 160rpx;
    background: #f2f2f2;
    border-radius: 10rpx;
    opacity: 1;
    font-size: 24rpx;
    line-height: 34rpx;
    margin-bottom: 20rpx;
  }
  .show {
    text-align: right;
    font-size: 24rpx;
    color: #64b6a8;
    line-height: 34rpx;
    padding-bottom: 20rpx;
  }
  .window_btn_box {
    display: flex;
    .window_btn {
      width: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 90rpx;
      background: #f2f2f2;
      font-size: 30rpx;
    }
    .window_btn1 {
      color: #fff;
      background: #64b6a8;
    }
  }
}
</style>
